﻿using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.DTO;
using mendian;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.尺寸
{
    public partial class Form尺寸更改 : DevExpress.XtraEditors.XtraForm
    {
        private DTOStyleMeasureItems dTOStyleMeasureItems;
        private String id;
        public Form尺寸更改()
        {
            InitializeComponent();
        }

        public Form尺寸更改(DTOStyleMeasureItems dTOStyleMeasureItems, String id)
        {
            InitializeComponent();
            this.dTOStyleMeasureItems = dTOStyleMeasureItems;
            this.id = id;
            this.值();
        }

        private void 值()
        {
            for (int i = 0; i < this.dTOStyleMeasureItems.measureItemDTOS.Count; i++)
            {
                if (this.dTOStyleMeasureItems.measureItemDTOS[i].id.Equals(id))
                {
                    this.textBox试样衣尺寸.Text = this.dTOStyleMeasureItems.measureItemDTOS[i].itemFitValue.ToString();
                    this.textBox客户净量体.Text = this.dTOStyleMeasureItems.measureItemDTOS[i].customerFitValue.ToString();
                    this.textBox尺寸名称.Text = this.dTOStyleMeasureItems.measureItemDTOS[i].itemNameCn;
                    this.textBox成衣尺寸.Text = this.dTOStyleMeasureItems.measureItemDTOS[i].garmentSize.ToString();
                    this.spinEdit加.Value = Convert.ToDecimal(this.dTOStyleMeasureItems.measureItemDTOS[i].inValue);
                    this.spinEdit减.Value = Convert.ToDecimal(this.dTOStyleMeasureItems.measureItemDTOS[i].outValue);
                }
            }
        }
        private void 算()
        {
            for (int i = 0; i < this.dTOStyleMeasureItems.measureItemDTOS.Count; i++)
            {
                if (this.dTOStyleMeasureItems.measureItemDTOS[i].id.Equals(id))
                {
                    this.dTOStyleMeasureItems.measureItemDTOS[i].inValue = Convert.ToDouble(this.spinEdit加.Value.ToString());
                    this.dTOStyleMeasureItems.measureItemDTOS[i].outValue = Convert.ToDouble(this.spinEdit减.Value.ToString());
                    String json = FunctionHelper.JsonSerialization(this.dTOStyleMeasureItems.measureItemDTOS[i]);
                    this.dTOStyleMeasureItems.measureItemDTOS[i] = FunctionHelper.JsonDeserialization<MeasureItemDTO>(RestCall.PostHttp(URL.接口url + "/style/saveMeasureItem?sessionId=" + this.dTOStyleMeasureItems.sessionId, json));
                    break;
                }
            }
            this.值();
        }

        private void numericUpDown加_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (((NumericUpDown)sender).Text.Trim().IndexOf('.') > -1)
            {
                if (((NumericUpDown)sender).Text.Trim().Substring(((NumericUpDown)sender).Text.Trim().IndexOf('.') + 1).Length >= 2)//定义小数位
                {
                    if (!char.IsDigit(e.KeyChar))
                    {
                        e.Handled = false;
                    }
                    else
                    {
                        e.Handled = true;
                    }
                }
            }
        }

        private void numericUpDown减_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (((NumericUpDown)sender).Text.Trim().IndexOf('.') > -1)
            {
                if (((NumericUpDown)sender).Text.Trim().Substring(((NumericUpDown)sender).Text.Trim().IndexOf('.') + 1).Length >= 2)//定义小数位
                {
                    if (!char.IsDigit(e.KeyChar))
                    {
                        e.Handled = false;
                    }
                    else
                    {
                        e.Handled = true;
                    }
                }
            }
        }

        private void spinEdit加_ValueChanged(object sender, EventArgs e)
        {
            this.算();
        }

        private void spinEdit减_ValueChanged(object sender, EventArgs e)
        {
            this.算();
        }

        private void spinEdit加_Click(object sender, EventArgs e)
        {
            this.spinEdit加.SelectAll();
        }

        private void spinEdit减_Click(object sender, EventArgs e)
        {
            this.spinEdit减.SelectAll();
        }
    }
}
